package echat.future.cn.echat.home

import android.os.Bundle
import com.bumptech.glide.Glide
import com.zhusx.core.app._BaseAppCompatActivity
import com.zhusx.core.imp.SimpleRecyclerAdapter
import com.zhusx.core.interfaces.IHttpResult
import com.zhusx.core.network.HttpRequest
import echat.future.cn.echat.R
import echat.future.cn.echat.home.bean.PresentEntity
import echat.future.cn.echat.home.bean.PresentItem
import echat.future.cn.echat.home.network.LoadData
import echat.future.cn.echat.home.network.SimpleHttpListener
import kotlinx.android.synthetic.main.activity_gift_total.*

/**
 *
 * Author  zhusx
 * Email   327270607@qq.com
 * Create  2018/8/9 23:35
 */
class GiftTotalActivity : _BaseAppCompatActivity() {
    private val listData by lazy {
        LoadData<PresentEntity>(LoadData.Api.用户礼物柜, this)
                .apply {
                    _setOnLoadingListener(object : SimpleHttpListener<PresentEntity>() {
                        override fun onLoadComplete(api: LoadData.Api, request: HttpRequest<Any>, result: IHttpResult<PresentEntity>) {
                            initView(result.data)
                        }
                    })
                }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_gift_total)
        val id = intent.getStringExtra(_EXTRA_String_ID)
        listData._loadData(id)
        iv_return.setOnClickListener { finish() }
    }

    private fun initView(data: PresentEntity) {
        tv_total.text = "${data.total}"
        recyclerView.adapter = object : SimpleRecyclerAdapter<PresentItem>(R.layout.list_item_gift, data.list) {
            override fun bindViewHolder(holder: _ViewHolder, p1: Int, s: PresentItem) {
                holder.run {
                    setText(R.id.tv_name, s.name)
                    setText(R.id.tv_value, "×${s.present_count}")
                    Glide.with(this@GiftTotalActivity).load(s.present_img).into(getView(R.id.iv_image))
                }
            }
        }
    }
}